home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / Terminal 2.2 / Terminal Folder / Sieve.s < prev   
Text File  |  1990-12-31  |  2KB  |  68 lines

  1. /*
  2.     Terminal 2.0
  3.     "Sieve.s"
  4.  
  5. This script was used to test the "Terminal" script interpreter. It is of no
  6. practical use. It is the standard Sieve benchmark often used to test the
  7. performance of computers. Note that because the "Terminal" script language
  8. is an interpreted language it is rather slow for loop intensive operations,
  9. but for its intended purpose as a communications script language it is fast
  10. enough.
  11.  
  12. The timing results were as follows (compared to the same program compiled
  13. with a real C compiler), Terminal compiled with THINK C 4.0
  14.  
  15.     Macintosh IIcx             : 108 seconds ( 43.2 ms ==> 2500 times)
  16.      Macintosh IIcx 68020 option: 108 seconds
  17.     Macintosh Plus             : 536 seconds (271.0 ms ==> 1978 times)
  18.  
  19. Terminal compiled with MPW 3.0
  20.  
  21.     Macintosh IIcx             :  93 seconds (86 % of THINK C version)
  22.     Macintosh IIcx 68020 option:  91 seconds (84 % of THINK C version)
  23.     Macintosh Plus             : 503 seconds (93 % of THINK C version)
  24. */
  25.  
  26. int SIZE = 8191;
  27. int LAUF = 1;
  28. char FALSE = 0;
  29. char TRUE = 1;
  30.  
  31. main()
  32. {
  33.     int tick, iter, count, i, k, prime;
  34.     char *flags, *p;
  35.  
  36.     display("Sieve benchmark %i passes\rThis may take several minutes...\r",
  37.         LAUF);
  38.     if (!(flags = new(SIZE))) {
  39.         display("Not enough memory\r")
  40.         return;
  41.     }
  42.     tick = time();                            /* <====== start */
  43.  
  44.     for (iter = 0; iter < LAUF; ++iter) {
  45.         count = 0;
  46.         p = flags + SIZE;
  47.         while (p > flags)
  48.             *(--p) = TRUE;
  49.         /* p == flags */
  50.         for (i = 0; i < SIZE; ++i) {
  51.             if (*p) {
  52.                 k = i + (prime = i + i + 3);
  53.                 while (k < SIZE) {
  54.                     flags[k] = FALSE;
  55.                     k = k + prime;
  56.                 }
  57.                 ++count;
  58.                 /*display("%i\r", prime);*/
  59.             }
  60.             ++p;
  61.         }
  62.     }
  63.  
  64.     tick = time() - tick;                    /* <====== stop */
  65.     free(flags);
  66.     display("%i primes in %i seconds\r", count, tick);
  67. }
  68.